using System;
using System.Collections.Generic;
using System.Text;

using phorm.model.fields;

namespace phorm.database.core
{
    /// <summary>
    /// Abstract database record class (aka table). Cannot be instantiated as it should be extended by an object in the Model.
    /// </summary>
    public abstract class DatabaseRecord
    {
        /// <summary>
        /// Constant string representing a record's self (used when object name is the same as relative).
        /// </summary>
        public const string SELF     = "_self";
        /// <summary>
        /// Constant string representing a record's relative (used when object name is the same as relative).
        /// </summary>
        public const string RELATIVE = "_relative";

        /// <summary>
        /// The columns stored in this record
        /// </summary>
        public ColumnsDictionary columns = new ColumnsDictionary();
        /// <summary>
        /// The primary key for this record
        /// </summary>
        public PrimaryKey primary_key;
        /// <summary>
        /// Set to true if the object is a new instance (i.e. - no saves have been called).
        /// </summary>
        public Boolean IsNew = true;

        /// <summary>
        /// Add a column to the columns dictionary
        /// </summary>
        /// <param name="key">Column name</param>
        /// <param name="value">DatabaseColumn itself</param>
        public void addColumn(string key, DatabaseColumn value)
        {
            columns.addColumn(key, value);
        }

        /// <summary>
        /// Create the table command using the appropriate CRUD.
        /// </summary>
        /// <returns>Create command from CRUD</returns>
        virtual public string create()
        {
            return null;
        }

        /// <summary>
        /// Create a many-to-many relationship command using appropriate CRUD.
        /// </summary>
        /// <param name="column">Many-to-many column</param>
        /// <returns>Create command from CRUD</returns>
        virtual public string createManyToMany(BaseManyToMany column)
        {
            return null;
        }

        /// <summary>
        /// Create a drop table command using the appropriate CRUD.
        /// </summary>
        /// <returns>Drop command from CRUD</returns>
        virtual public string drop()
        {
            return null;
        }

        /// <summary>
        /// Create an empty table command using the appropriate CRUD.
        /// </summary>
        /// <returns>Empty command from CRUD</returns>
        virtual public string empty()
        {
            return null;
        }

        /// <summary>
        /// Initialize the object with data from a Primary Key.
        /// </summary>
        /// <param name="id">Primary Key object</param>
        virtual public void initWithId(object id){ }

        /// <summary>
        /// Save this object to the database.
        /// </summary>
        virtual public void save(){}

        /// <summary>
        /// Delete this object from the database.
        /// </summary>
        virtual public void delete(){}
    }
}
